package com.ymt.bpm.engine.handler.gateway;

import com.alibaba.fastjson.JSONObject;
import com.ymt.bpm.dao.MDao;
import com.ymt.bpm.dao.Mapper;
import com.ymt.bpm.engine.EngineConst;
import com.ymt.bpm.engine.bpmn.ProcessUtil;
import com.ymt.bpm.engine.handler.ActivityEventHandler;
import com.ymt.bpm.model.PPi;
import com.ymt.bpm.service.engine.bpd.BpdVersionCacheService;
import com.ymt.bpm.util.Const;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.delegate.event.ActivitiActivityEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by Johnny on 2016/12/24.
 */
@Component
public class ParallelGatewayHandler implements ActivityEventHandler {

    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private RuntimeService rs;

    @Autowired
    private MDao dao;

    @Autowired
    BpdVersionCacheService bvcs;

    @Override
    public void onActivityStarted(ActivitiActivityEvent aae) {
        String tenantId = (String) rs.getVariable(aae.getExecutionId(), Const.TENANT_ID);
        if (log.isDebugEnabled()) {
            log.debug("onActivityStarted tenantId="+tenantId);
            log.debug("onActivityStarted ExclusiveGatewayHandler getBehaviorClass="+aae.getBehaviorClass());
            log.debug("onActivityStarted ExclusiveGatewayHandler gatewayId="+aae.getActivityId());
            log.debug("onActivityStarted ExclusiveGatewayHandler gatewayId="+aae.getActivityName());
            log.debug("onActivityStarted gatewayName="+aae.getActivityName());
            log.debug("onActivityStarted executionId="+aae.getExecutionId());
            log.debug("onActivityStarted variables="+rs.getVariables(aae.getExecutionId()));
        }
    }

    @Override
    public void onActivityComplete(ActivitiActivityEvent aae) {
        if (log.isDebugEnabled()) {
            log.debug("onActivityComplete ExclusiveGatewayHandler gatewayId="+aae.getActivityId());
            log.debug("onActivityComplete gatewayName="+aae.getActivityName());
            log.debug("onActivityComplete executionId="+aae.getExecutionId());
            log.debug("onActivityComplete variables="+rs.getVariables(aae.getExecutionId()));
        }
    }

}
